import socket


def udp_service():
    # SOCK_DGRAM指定了这个Socket的类型是UDP
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(('127.0.0.1', 9999))
    print('bind UDP on 9999...')
    while True:
        # 接收数据
        data, addr = s.recvfrom(1024)
        print('received from %s:%s.' % addr)
        s.sendto(b'hello,%s!' % data, addr)
